package com.qqb.controller;

import com.qqb.pojo.Job;
import com.qqb.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/job")
public class JobController {

    @Resource
    private RedisTemplate redisTemplate;

    @Autowired
    private JobService jobService;

    /**
     * 从redis中查询所有学历列表，如果缓存中不存在，再去数据库中查找
     *
     * @return
     */
    @GetMapping("/findAll")
    public List<Job> findAll() {
        List<Job> jobList;
        jobList = (List<Job>) redisTemplate.boundValueOps("Job").get();
        if (jobList == null || jobList.isEmpty()) {
            jobList = jobService.findAll();
        }
        return jobList;
    }
}
